package zyq.web;



import zyq.ai.WebFaceCompare;

import zyq.entity.RecognitonResponse;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.multipart.MultipartFile;



import java.io.File;



/**

 * TODO

 *

 * @author My

 * @date 2021/10/12 16:05

 */

@RestController

public class UploadController {



    @PostMapping(value = "/upload")

    public Object upload(@RequestParam("file") MultipartFile file){

        try{

            String fileName = file.getOriginalFilename();

            String savePath = "E:\\temp";

            File savePathDir = new File(savePath);

            if(!savePathDir.exists()){

                savePathDir.mkdirs();

            }



            File imgFile = new File(savePath + "/" + fileName);

            file.transferTo(imgFile);



            RecognitonResponse response = WebFaceCompare.service(imgFile.getAbsolutePath());

            return response;

        }catch (Exception e){

            e.printStackTrace();

        }



        return null;

    }

}

